package com.rain.core.saver;

import com.rain.ai.model.HtmlCodeResult;
import com.rain.exception.BusinessException;
import com.rain.exception.ErrorCode;
import com.rain.enums.CodeGenTypeEnum;

public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {
    @Override
    protected void validFile(HtmlCodeResult result) {
        super.validFile(result);
        if(result.getHtmlCode()==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"htmlCode不能为空");
        }
    }

    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());
    }
}
